package cn.kgm.makeGod.action;

import cn.kgm.makeGod.Character;
import cn.kgm.makeGod.Relationship;
import cn.kgm.makeGod.RelationshipType;
import cn.kgm.makeGod.condition.EventResult;
import cn.kgm.makeGod.condition.WorldState;
import lombok.Builder;
import lombok.Data;

/**
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-9-11 15:02
 * @Description: cn.kgm.makeGod.action.ExchangeItemAction
 */
@Data
@Builder
public class ExchangeItemAction implements Action {
    private String itemType;
    private boolean request; // true为请求物品，false为赠送物品

    public ExchangeItemAction() {
    }

    public ExchangeItemAction(String itemType, boolean request) {
        this.itemType = itemType;
        this.request = request;
    }

    @Override
    public void execute(Character actor, Character target, WorldState world, EventResult result) {
        // 简化的物品交换逻辑
        if (request) {
            result.addLog(actor.getName() + " 向 " + target.getName() + " 请求一件" + itemType);

            // 根据关系决定是否同意
            Relationship rel = target.getRelationshipTo(actor.getId());
            if (rel != null && rel.getValue() > 60) {
                result.addLog(target.getName() + " 慷慨地答应了请求");
                // 关系提升
                rel.setValue(rel.getValue() + 5);
            } else {
                result.addLog(target.getName() + " 拒绝了请求");
                if (rel != null) {
                    rel.setValue(rel.getValue() - 5);
                }
            }
        } else {
            result.addLog(actor.getName() + " 赠送给 " + target.getName() + " 一件" + itemType);

            // 接收礼物
            Relationship rel = target.getRelationshipTo(actor.getId());
            if (rel != null) {
                rel.setValue(rel.getValue() + 10);
                result.addLog(target.getName() + " 很高兴，关系提升了");
            } else {
                target.addRelationship(new Relationship(
                        target.getId(), actor.getId(),
                        RelationshipType.FRIEND, 15
                ));
                result.addLog(target.getName() + " 对 " + actor.getName() + " 产生了好感");
            }
        }
    }
}
